package com.kjsdfgk.hjmdsf.login.mvp.ui.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import com.kjsdfgk.hjmdsf.app.entity.Account;
import com.kjsdfgk.hjmdsf.app.utils.SharedPrefsUtils;
import com.kjsdfgk.hjmdsf.login.di.component.DaggerLoginComponent;
import com.kjsdfgk.hjmdsf.login.mvp.contract.LoginContract;
import com.kjsdfgk.hjmdsf.login.mvp.presenter.LoginPresenter;
import com.kjsdfgk.hjmdsf.register.mvp.ui.activity.RegisterActivity;
import com.lksdkjs.live.R;


import butterknife.BindView;
import butterknife.OnClick;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 04/19/2020 00:43
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
public class LoginActivity extends BaseActivity<LoginPresenter> implements LoginContract.View {

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerLoginComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_login; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

    }

    @Override
    public void showLoading(String key) {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public boolean isCancel() {
        return false;
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }
    @BindView(R.id.login_account_et)
    EditText login_account_et;
    @BindView(R.id.login_password_et)
    EditText login_password_et;


    @OnClick({R.id.login_not_account_tv, R.id.login_confirm_tv  })
    public void onViewClicked(View view) {
        switch (view.getId()){
            case R.id.login_not_account_tv:
                startActivity(new Intent(this , RegisterActivity.class));
                break;
            case R.id.login_confirm_tv:
                String account = login_account_et.getText().toString();
                String password = login_password_et.getText().toString();
                if (TextUtils.isEmpty(account)){
                    showMessage("请确认账号");
                }else if (TextUtils.isEmpty(password)){
                    showMessage("请输入密码");
                }else {
                    mPresenter.userLogon(account , password);
                }
                break;

        }


    }

    @Override
    public void showAccount(Account info) {
        showMessage("登录成功");
        finish();
    }
}
